import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_app_05/action/states/dark_states.dart';
import 'package:flutter_app_05/action/states/data_manager.dart';
import 'package:flutter_app_05/http/HttpRequest.dart';
import 'package:flutter_app_05/utils/MyTheme.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:provider/provider.dart';


class Padecalfour extends StatefulWidget{
  @override
  _PadecalfouroInState createState() => _PadecalfouroInState();

}

class _PadecalfouroInState extends State<Padecalfour>{
  TextEditingController dtCon=new TextEditingController();
  TextEditingController lenCon=new TextEditingController();
  TextEditingController kCon=new TextEditingController();
  TextEditingController conffitCon=new TextEditingController();
  String html="<p/>";
  @override
  Widget build(BuildContext context) {
    return Consumer<DartState>(builder: (context, categoryState, child) {
      return columns(categoryState);
    });
  }

  Widget columns(DartState categoryState) {
    Widget h=Container(height: 1,color:  MyTheme(context).getColor("line_color"),alignment: Alignment.center,margin: EdgeInsets.only(top: 10.0,bottom: 10.0),);
    return Container(
      color: MyTheme(context).getColor("bg"),
      child: Column(
        children: [
          Container(
            margin: EdgeInsets.all(10.0),
            padding: EdgeInsets.all(15),
            decoration: new BoxDecoration(
                color: MyTheme(context).getColor("white"),
                borderRadius: new BorderRadius.circular((10.0))),
            alignment: Alignment.center,
            height: 170,
            child: Column(
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: [
                    Text("*",style: TextStyle(color: Colors.red),),
                    Expanded(child:  Text("温度",style: TextStyle(color: MyTheme(context).getColor('colorBlack')),)),
                    Container(
                      width: 100,
                      child: TextField(
                      textAlign: TextAlign.right,
                        maxLength: 100,
                        decoration: null,
                        controller: dtCon,
                        inputFormatters: [WhitelistingTextInputFormatter.digitsOnly],
                        style: TextStyle(color: Colors.green),

                      ),
                    ),
                    Text("℃",style: TextStyle(color: MyTheme(context).getColor('colorBlack')),),
                  ],
                ),
                h,
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: [
                    Text("*",style: TextStyle(color: Colors.red),),
                    Expanded(child:  Text("长度",style: TextStyle(color: MyTheme(context).getColor('colorBlack')),)),
                    Container(
                      width: 100,
                      child: TextField(
                        textAlign: TextAlign.right,
                        maxLength: 100,
                        decoration: null,
                        controller: lenCon,
                        inputFormatters: [WhitelistingTextInputFormatter.digitsOnly],
                        style: TextStyle(color: Colors.green),

                      ),
                    ),
                    Text("m",style: TextStyle(color: MyTheme(context).getColor('colorBlack')),),
                  ],
                ),
                h,
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: [

                    Expanded(child:  Text("  热膨胀系数",style: TextStyle(color: MyTheme(context).getColor('colorBlack')),)),
                    Container(
                      width: 100.0,
                      child: TextField(
                        textAlign: TextAlign.right,
                        maxLength: 100,
                        decoration: null,
                        controller: conffitCon,
                        inputFormatters: [WhitelistingTextInputFormatter.digitsOnly],
                        style: TextStyle(color: MyTheme(context).getColor('colorBlack')),

                      ),
                    ),
                    Text("1/℃",style: TextStyle(color: MyTheme(context).getColor('colorBlack')),),
                  ],
                ),
                h,

              ],
            ),
          ),
          Center(child: Html(

              data: html),

          ),
          Expanded(
              child: Stack(
                children: [
                  Positioned(
                    child: Container(
                      height: 60.0,

                      alignment: Alignment.bottomCenter,
                      child: Row(
                        children: [
                          Expanded(
                            child: GestureDetector(
                              child: Container(
                                color: MyTheme(context).getColor("white"),
                                child: Center(
                                  child: Text(
                                    "重置",
                                    style: new TextStyle(fontSize: 25.0,color: MyTheme(context).getColor('text_color')),
                                  ),
                                ),
                              ),
                              onTap: () {
                                dtCon.text="";
                                lenCon.text="";
                                kCon.text="";
                                conffitCon.text="";
                              },
                            ),
                          ),
                          Expanded(
                            child: GestureDetector(
                              child:   Container(
                                color: Colors.green,

                                child: Center(
                                  child: Text(
                                    "提交",
                                    style: new TextStyle(fontSize: 25.0,color: Colors.white),
                                  ),
                                ),
                              ),

                              onTap: (){
                                getpz();
                                setState(() {

                                });
                              },
                            ),
                          )
                        ],
                      ),
                    ),
                    bottom: 0,
                    left: 0,
                    right: 0,
                  ),
                ],
              )),

        ],
      ),
    );
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  Future getpz()async{
    await DataManager.getPzxs(p:{"dtemp":dtCon.text,"len":lenCon.text,"k":lenCon.text,"coefficient":"1","from":"IOS"},).then((value) {
      if(value.data==null){
        html=value.msg;
      }else{
        html=value.data;
      }
setState(() {

});
    });
  }

}

